/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	RenderEntryWindowViewPresent.cpp
*
*	Comments	-	See RenderEntryWindowViewPresent.h
*
**************************************************************************************/
#include "../Include/RenderEntryWindowViewPresent.h"
#include "../Include/Model.h"

namespace Pulse
{
	RenderEntryWindowViewPresent::RenderEntryWindowViewPresent( void )
		: m_pParams( PSX_NULL ), m_pNDCQuadModel( PSX_NULL )
	{

	}

	RenderEntryWindowViewPresent::~RenderEntryWindowViewPresent( void )
	{
		Clear();
	}

	void RenderEntryWindowViewPresent::Execute( GraphicsPipeline *pPipeline )
	{
		if ( m_pParams )
		{
			m_pParams->BindParameters();
		}

		const SIZE_T numEntries = m_modelRenderEntries.GetNumEntries();
		RenderEntry **pEntries = m_modelRenderEntries.GetRenderEntries();
		RenderEntry *pEntry;

		for ( SIZE_T i = 0; i < numEntries; ++i )
		{
			pEntry = pEntries[i];

			pEntry->PreExecute( pPipeline );
			pEntry->Execute( pPipeline );
			pEntry->PostExecute( pPipeline );
		}
	}

	void RenderEntryWindowViewPresent::SetParameterContainer( ParameterContainer *pParams )
	{
		m_pParams = pParams;
	}

	void RenderEntryWindowViewPresent::SetModel( Model *pModel )
	{
		PSX_SafeRelease( m_pNDCQuadModel );

		m_pNDCQuadModel = pModel;

		if ( pModel )
		{
			pModel->AddRef();
		}
	}

	void RenderEntryWindowViewPresent::Clear( void )
	{
		m_pParams = PSX_NULL;
		PSX_SafeRelease( m_pNDCQuadModel );
		m_modelRenderEntries.ClearRenderEntries();
	}

}